<?php
define('TDIR',dirname(__FILE__));
//include_once TDIR.'/config.php';
if(isset($_REQUEST['go'])){
	$a=base_convert($_GET['a'],36,10);
	//if($a<300)$a=base_convert($_GET['a'],16,10);
	$d=$a%100;
	$g=($a-$d)/100;
	if(!file_exists(TDIR.'/data/'.$g.'.php')){
		$tv=array('URL Not Exists','go.notexists');
		include_once TDIR.'/inctpl.php';
	}else{
		include_once TDIR.'/data/'.$g.'.php';
		if(isset($t[$d])){
			$tUrl=$t[$d];
			switch($_GET['method']){
				case 'click':
					$tv=array('请点击链接跳转','go.click');
					include_once TDIR.'/inctpl.php';
					break;
				case 'javascript':
					$tv=array('正在跳转，请等待……','go.html');
					$tv[3]='<script src="'.str_replace('//','/',strtr(dirname($_SERVER['SCRIPT_NAME']).'/jump.js','\\','/')).'" type="text/javascript"></script><script type="text/javascript">jumpTo("'.str_replace('"','\\"',$tUrl).'");</script>';
					include_once TDIR.'/inctpl.php';
					break;
				case 'html':
					$tv=array('正在跳转，请等待……','go.html');
					$tv[3]='<meta http-equiv="refresh" content="1;url='.$tUrl.'"/>';
					include_once TDIR.'/inctpl.php';
					break;
				case 'header':
					header('Location: '.$tUrl);
					break;
				default:
					header('Location: '.$tUrl);
					break;
			}
		}else{
			header('Location: /');
		}
	}
}elseif($_POST['url']){
	$a=file_get_contents(TDIR.'/data/n.txt');
	$d=$a%100;
	$g=($a-$d)/100;
	file_exists('data/'.$g.'.php') or file_put_contents('data/'.$g.'.php',"<?php\r\n");
	file_put_contents('data/'.$g.'.php','$t['.$d.']=\''.$_POST['url'].'\';'."\r\n",FILE_APPEND);
	file_put_contents('n.txt',$a+1);
	$outUrl='http://'.$_SERVER['HTTP_HOST'].'/'.base_convert($a,10,36);
	$tv=array('输出链接','output');
	include_once TDIR.'/inctpl.php';
}else{
	$tv=array('输入链接','mainform');
	include_once TDIR.'/inctpl.php';
}
?>